package com.yiyuan.app.controller;

import com.alipay.api.AlipayApiException;
import com.guaike.core.entity.result.Result;
import com.yiyuan.app.entity.param.IosPayResultDTO;
import com.yiyuan.app.entity.param.RepayDTO;
import com.yiyuan.app.entity.param.UseEquityDTO;
import com.yiyuan.app.entity.result.RepayVO;
import com.yiyuan.app.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/pay")
@Api(tags = "充值相关接口组")
@AllArgsConstructor
public class PayController {

    private final PayService payService;

    @GetMapping("/repayProduct")
    @ApiOperation(value = "预支付请求")
    public Result<RepayVO> repayProduct(@Valid RepayDTO param) throws AlipayApiException {
        return payService.repayProduct(param);
    }

    @PostMapping("/useEquity")
    @ApiOperation(value = "使用特权")
    public Result<Boolean> useEquity(@Valid @RequestBody UseEquityDTO param) throws IOException, InterruptedException {
        return payService.useEquity(param);
    }

    @PostMapping("/dealIosPayResult")
    @ApiOperation(value = "苹果支付成功结构校验")
    public Result<Boolean> dealIosPayResult(@Valid @RequestBody IosPayResultDTO param) throws Exception {
        return payService.dealIosPayResult(param);
    }
}
